package randomthoughts.dp;

/**
 * @author tongchen
 * @create 2023-04-16 22:57
 */
public class CombinedSum {
    public static void main(String[] args) {
        int[]nums=new int[]{1,1,1,1,1};
        int  sum=3;
        askMethodSum(nums,sum);
    }
    public static int askMethodSum(int[]nums,int target){
     //创建dp
        int[]dp=new int[target+1];
        //初始化
        dp[0]=1;
        //进行遍历，容量，再遍历元素
        for(int i=1;i<=target;++i){
            for (int j = 0; j < nums.length ; j++) {
                if(i>=nums[j]){
                    dp[i]+=dp[i-nums[j]];
                }
            }
        }
        for (int i = 0; i < dp.length ; i++) {
            System.out.print(dp[i]+" ");
        }
        return dp[target];

    }
}
